package hash;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @Auther: liwenhao
 * @Date: 2022/5/12 16:36
 * @Description:
 */
public class MyHashMap<K, V> {

    // aka 16
    static final int DEFAULT_INITIAL_CAPACITY = 1 << 4;

    transient Node<K, V>[] table;

    public MyHashMap() {
        table = new Node[DEFAULT_INITIAL_CAPACITY];
    }

    public void put(K k, V v){
        HashMap<String, String> map = new HashMap<>();
        map.put("12","12");
        map.remove("12");
        putVal(hash(k), k, v);
    }

    private void putVal(int hash, K key, V value) {
        Node<K, V> p;
        int n,i;
        n = table.length;
        if ((p = table[i = (n - 1) & hash]) == null) {
            table[i] = new Node<>(hash, key, value, null);
        } else {
            K k;
            if (p.hash == hash ||
                    ((k = p.key) ==  key|| (k != null && key.equals(k)))) {

            }
        }
    }

    public V get(K k){
        return table[hash(k)].value;
    }

    public void remove(K k){

    }



    static class Node<K,V>  {
        final int hash;
        final K key;
        V value;
        Node<K,V> next;

        Node(int hash, K key, V value, Node<K,V> next) {
            this.hash = hash;
            this.key = key;
            this.value = value;
            this.next = next;
        }

        public final K getKey()        { return key; }
        public final V getValue()      { return value; }
        @Override
        public final String toString() { return key + "=" + value; }

        @Override
        public final int hashCode() {
            return Objects.hashCode(key) ^ Objects.hashCode(value);
        }

        public final V setValue(V newValue) {
            V oldValue = value;
            value = newValue;
            return oldValue;
        }

        @Override
        public final boolean equals(Object o) {
            if (o == this) {
                return true;
            }
            if (o instanceof Map.Entry) {
                Map.Entry<?,?> e = (Map.Entry<?,?>)o;
                if (Objects.equals(key, e.getKey()) &&
                        Objects.equals(value, e.getValue())) {
                    return true;
                }
            }
            return false;
        }
    }

    static final int hash(Object key) {
        int h;
        return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
    }

}
